
#include <Encoder.h>
#include <PID_v1.h>

// Change these pin numbers to the pins connected to your encoder.
//   Best Performance: both pins have interrupt capability
//   Good Performance: only the first pin has interrupt capability
//   Low Performance:  neither pin has interrupt capability
Encoder actuator(18, 19); // 18 is red, 19 is black
//   avoid using pins with LEDs attached
int c2=1;
unsigned long time;
unsigned long time2;
long encoder_range;
int ACT1 = 9; //pin 9 for actuator 1

//Define Variables we'll be connecting to


//Specify the links and initial tuning parameters


void setup() {
  Serial.begin(9600);
  Serial.println("Encoder Test:");
 // Input = actuator.read();


  
//TCCR3B = TCCR3B & 0b1111000 | 0x01; // 5 is on timer 3
TCCR2B = TCCR2B & 0b1111000 | 0x01;

//calibrate end points of claw range of motion, 
//grab encoder values at these boundary points

analogWrite(ACT1,127); // stop

}

void loop() {
 int val2;
  long newAct;
  newAct = actuator.read();
  Serial.println(newAct);
  
    if (Serial.available()) {
    int val=Serial.read();
    val2 = 127;
    switch(val){ // switch between open/close/noting with arrow keys 1,2,3
    case 49:
    val2=100;
    break;
    case 50:
    val2= 127;
    break;
    case 51:
    val2 = 150;
    break;
    }
    
    Serial.println(val2);
    Serial.println("Reset both knobs to zero");
    analogWrite(ACT1,127); // stop
  }

  
}

